home *** CD-ROM | disk | FTP | other *** search
- /* File: Recorder.c
-
- MPW Tool for dumping recorder files
-
- */
-
-
- #include <Types.h>
- #include <QuickDraw.h>
- #include <Files.h>
- #include <Strings.h>
-
- #include <StdIO.h>
- #include <StdLib.h>
-
-
- #define ONE_LINE 16
- short lineCnt;
- short lastHeader;
- char *headers[] = { " ",
- "Computer -->",
- "Modem -->" };
-
- void DumpHexString ( char *theStr, short len ) {
- short filler;
- char *hex = "0123456789ABCDEF";
-
- filler = ONE_LINE - len;
- printf ( "$\"" );
- while ( len-- > 0 ) {
- printf ( " %c%c", hex [ ( *theStr >> 4 ) & 0x0F ], hex [ *theStr & 0x0F ] );
- theStr++;
- }
- putchar ( '"' );
- while ( filler-- > 0 )
- printf ( " " );
- }
-
- void DumpAsciiString ( char *theStr, short len ) {
- short filler;
-
- filler = ONE_LINE - len;
- printf ( "/* " );
- while ( len-- > 0 ) {
- if ( *theStr >= ' ' && *theStr <= '~' )
- putchar ( *theStr );
- else
- putchar ( '.' );
- theStr++;
- }
-
- while ( filler-- > 0 )
- putchar ( ' ' );
- printf ( " */" );
- }
-
-
- void DumpLine ( short header, char *theStr, short len ) {
-
- if ( len > 0 ) {
- header -= '0';
- printf ( "%s", headers [ header == lastHeader ? 0 : header ] );
- lastHeader = header;
-
- DumpHexString ( theStr, len );
- putchar ( '\t' );
- putchar ( '\t' );
- DumpAsciiString ( theStr, len );
- printf ( "\n" );
- lineCnt = 0;
- }
- }
-
-
- int main ( int argc, char *argv[] ) {
- short lastDir, dirChar;
- FILE *inf;
- char lineBuf [ ONE_LINE ];
-
- if ( argc != 2 ) {
- fprintf ( stderr, "Usage: %s <fileName>\n", argv [ 0 ] );
- exit ( 1 );
- }
-
- inf = fopen ( argv [ 1 ], "rb" );
- if ( inf == NULL ) {
- fprintf ( stderr, "Unable to open file %s", argv [ 1 ] );
- exit ( 2 );
- }
-
- lastDir = 0;
- lastHeader = -1;
- lineCnt = 0;
-
- do {
-
- /* End of file, we're done */
- if (( dirChar = fgetc ( inf )) == EOF ) {
- DumpLine ( lastDir, lineBuf, lineCnt );
- break;
- }
-
- /* Switch data flow */
- if ( dirChar != lastDir ) {
- DumpLine ( lastDir, lineBuf, lineCnt );
- lastDir = dirChar;
- }
-
- lineBuf [ lineCnt++ ] = fgetc ( inf );
- if ( lineCnt == ONE_LINE )
- DumpLine ( lastDir, lineBuf, lineCnt );
-
- } while ( true );
-
- fclose ( inf );
- return 0;
- }
-